/**
 * com.cnhis.his.customer.service.Bak1Service.java
 */
package com.mbmed.doctor.homepage.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.homepage.bo.Bak1Bo;
import com.mbmed.doctor.homepage.mapper.Baf1;
import com.mbmed.doctor.homepage.mapper.Bak1;

/**
 * @file  Bak1Service.java
 * @author 刘武
 * @version 0.1
 * @todo	Bak1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-11-25 01:31:55
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/bak1")
@Component
public class Bak1Service {
	
	private static Logger logger = Logger.getLogger(Bak1.class);
	
	@Autowired
	private Bak1Bo bak1Bo;
	
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Bak1> getAll() throws Exception{
        List<Bak1> list = new ArrayList<Bak1>();
        return bak1Bo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Bak1 getBak1(@PathParam("id") String id) throws Exception{
    	Bak1 bak1 = null;
    	return bak1Bo.get(id);        
    }
	
	
	
	
	
	
	/**
     * 检索诊断
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getbak1bytext")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getBak1ByText(
    		@QueryParam("baf01") java.lang.String baf01,
    		@QueryParam("txt") java.lang.String txt,
    		@QueryParam("starid") java.lang.String starid,
    		@QueryParam("endid") java.lang.String endid
    		) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("baf01", baf01);
		map.put("txt",txt);
		map.put("starid", Integer.parseInt(starid));
		map.put("endid", Integer.parseInt(endid));
		ModelVo modelvo = new ModelVo();
		List<Bak1>  list = new ArrayList<Bak1>();
		list = bak1Bo.getBak1ByText(map);
		
		Bak1 bak1 = new Bak1();
		bak1 = bak1Bo.getBak1CountByText(map);
		modelvo.setResult(bak1.getCout()+"");
		modelvo.setList(list);
    	return modelvo;
	}
	
	
	/**
     * 检索诊断
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getbak1twobytext")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getBak1TwoByText(
    		@QueryParam("baf01") java.lang.String baf01,
    		@QueryParam("txt") java.lang.String txt,
    		@QueryParam("starid") java.lang.String starid,
    		@QueryParam("endid") java.lang.String endid
    		) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("baf011", baf01.substring(0,1));
		map.put("baf012", baf01.substring(1,2));
		map.put("txt",txt);
		map.put("starid", Integer.parseInt(starid));
		map.put("endid", Integer.parseInt(endid));
		ModelVo modelvo = new ModelVo();
		List<Bak1>  list = new ArrayList<Bak1>();
		list = bak1Bo.getBak1TwoByText(map);
		
		Bak1 bak1 = new Bak1();
		bak1 = bak1Bo.getBak1CountTwoByText(map);
		modelvo.setResult(bak1.getCout()+"");
		modelvo.setList(list);
    	return modelvo;
	}
	
	
	
	
    /**
     * 向数据库中插入一条记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Bak1 saveBak1(
			@FormParam("bak01") java.lang.Integer bak01,
			@FormParam("bak02") java.lang.String bak02,
			@FormParam("bak03") java.lang.Byte bak03,
			@FormParam("bak04") java.lang.String bak04,
			@FormParam("bak05") java.lang.String bak05,
			@FormParam("bak06") java.lang.String bak06,
			@FormParam("bak07") java.lang.String bak07,
			@FormParam("abbrp") java.lang.String abbrp,
			@FormParam("abbrw") java.lang.String abbrw,
			@FormParam("abw01") java.lang.String abw01,
			@FormParam("abx01") java.lang.String abx01,
			@FormParam("bak12") java.lang.Byte bak12,
			@FormParam("ach01") java.lang.String ach01,
			@FormParam("bak14") java.lang.String bak14,
			@FormParam("baf01") java.lang.String baf01,
			@FormParam("bah01") java.lang.Integer bah01,
			@FormParam("bak17") java.util.Date bak17,
			@Context HttpServletResponse servletResponse
	) throws Exception {
		Bak1 bak1 = new Bak1();
		bak1.setBak01(bak01);
		bak1.setBak02(bak02);
		bak1.setBak03(bak03);
		bak1.setBak04(bak04);
		bak1.setBak05(bak05);
		bak1.setBak06(bak06);
		bak1.setBak07(bak07);
		bak1.setAbbrp(abbrp);
		bak1.setAbbrw(abbrw);
		bak1.setAbw01(abw01);
		bak1.setAbx01(abx01);
		bak1.setBak12(bak12);
		bak1.setAch01(ach01);
		bak1.setBak14(bak14);
		bak1.setBaf01(baf01);
		bak1.setBah01(bah01);
		bak1.setBak17(bak17);

		return bak1 = bak1Bo.save(bak1);

	}
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeBak1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return bak1Bo.remove(id);

	}
	
}
